import turtle
import random

def draw_haloxylon_tree():
    # 设置画布
    screen = turtle.Screen()
    screen.title("绿色梭梭树")
    screen.bgcolor("skyblue")
    
    # 创建画笔
    pen = turtle.Turtle()
    pen.speed(5)  # 绘制速度
    pen.left(90)  # 向上
    pen.up()      # 抬笔
    pen.backward(200)  # 向下移动一点
    pen.down()    # 落笔
    pen.color("saddlebrown")  # 树干颜色
    
    # 绘制树干
    trunk_length = 100
    pen.pensize(8)
    pen.forward(trunk_length)
    
    # 绘制树枝
    def draw_branches(length, level, pensize):
        # 减小画笔大小
        if pensize > 2:
            new_pensize = pensize - 1
        else:
            new_pensize = 2
        pen.pensize(new_pensize)
        
        # 递归结束条件
        if level < 1:
            return
            
        # 保存当前状态（位置和角度）
        current_pos = pen.pos()
        current_heading = pen.heading()
        
        # 右分支
        pen.right(30)
        pen.forward(length)
        # 绘制叶子
        if level == 1:
            pen.color("green")
            pen.circle(3)  # 小圆形叶子
            pen.color("saddlebrown")
        draw_branches(length * 0.7, level - 1, new_pensize)
        
        # 恢复状态
        pen.penup()
        pen.setpos(current_pos)
        pen.setheading(current_heading)
        pen.pendown()
        
        # 左分支
        pen.left(30)
        pen.forward(length)
        # 绘制叶子
        if level == 1:
            pen.color("green")
            pen.circle(3)  # 小圆形叶子
            pen.color("saddlebrown")
        draw_branches(length * 0.7, level - 1, new_pensize)
        
        # 恢复状态
        pen.penup()
        pen.setpos(current_pos)
        pen.setheading(current_heading)
        pen.pendown()
    
    # 开始绘制树枝，长度、层级和初始画笔大小
    draw_branches(60, 3, 6)
    
    # 再添加一些细枝，模拟梭梭树的特征
    pen.penup()
    pen.backward(trunk_length * 0.6)
    pen.pensize(4)
    pen.pendown()
    
    # 右侧细枝
    pen.right(20)
    pen.forward(40)
    draw_branches(30, 2, 3)
    
    pen.penup()
    pen.backward(40)
    pen.left(20)
    pen.backward(30)
    pen.pendown()
    
    # 左侧细枝
    pen.left(20)
    pen.forward(40)
    draw_branches(30, 2, 3)
    
    # 隐藏画笔
    pen.hideturtle()
    
    # 保持窗口打开
    screen.exitonclick()

# 调用函数绘制梭梭树
draw_haloxylon_tree()
    